<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1 id="h1"></h1>
<script>
    function fn(){
var now= new Date()*1  
var nox= new Date(2022,1,1)*1
var cha = nox-now;
console.log(cha);
var t = 24*60*60*1000
var h = 60*60*1000
var f = 60*1000
var tt=Math.floor(cha/t)
var hh=Math.floor(cha%t/h)
var ff=Math.floor(cha%h/f)
var ss=Math.floor(cha%f/1000)
// console.log(tt,hh,ff,ss);

h1.innerHTML=`距离元旦还有${tt}天${bl(hh)}小时${bl(ff)}分钟${bl(ss)}秒`

}
fn()
function bl(z){
   
return z<10?"0"+z:z
}
setInterval(fn,1000)

</script>  
</body> 

</html>